package com.org.sort;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.ForkJoinTask;

@SuppressWarnings("serial")
public class ListConcurrentSortComparable<T extends Comparable<? super T>> extends AbConcurrentListSort<T> {

    public ListConcurrentSortComparable(List<T> list) {
        super(list);
    }

    public ListConcurrentSortComparable(List<T> list, int threadloads) {
        super(list, threadloads);
    }

    private ListConcurrentSortComparable(List<T> list, int start, int end, int threadloads) {
        super(list, start, end, threadloads);
    }

    @Override
    public void sortRange(int start, int end) {
        Collections.sort(list.subList(start, end));
    }

    @Override
    protected int compare(T t1, T t2) {
        return t1.compareTo(t2);
    }

    @Override
    protected ForkJoinTask<Void> invokeTaskLeft(int pos) {
        return new ListConcurrentSortComparable<>(list, began, pos - 1, threadloads);
    }

    @Override
    protected ForkJoinTask<Void> invokeTaskRight(int pos) {
        return new ListConcurrentSortComparable<>(list, pos + 1, end, threadloads);
    }

}
